package com.jt.ktdemo.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jt.ktdemo.R
import com.jt.ktdemo.bean.RcMessage
import com.jt.ktdemo.listener.OnItemSysClickListener

class SystemMessageDetailAdapter(layoutResId: Int, data: ArrayList<RcMessage>, context: Context) :
    BaseQuickAdapter<RcMessage, BaseViewHolder>(layoutResId, data) {

    private var datas = ArrayList<RcMessage>()
    private var aContext: Context? = null
    private lateinit var listener : OnItemSysClickListener

    init {
        aContext = context
        datas = data
    }

    fun setOnItemSysClickListener(listener:OnItemSysClickListener){
        this.listener = listener
    }

    override fun convert(helper: BaseViewHolder, item: RcMessage) {
        //消息标题
        helper.setText(R.id.tvModuleTitle, item.title)
        //消息内容
        helper.setText(R.id.tvModuleMessageContext, item.message)
        //消息时间
        helper.setText(R.id.tvModuleDate, item.createTimeNew)

        helper.setOnClickListener(R.id.rlModule,object:View.OnClickListener{
            override fun onClick(v: View?) {
                if (listener != null) {
                    listener.setOnItemSysClickListener(item.url,item.title)
                }
            }
        })
    }

    fun addListData(data: MutableList<RcMessage>) {
        val size = datas.size
        datas.addAll(size, data)
        notifyItemRangeChanged(size, data.size)
    }
}